package tech.aistar.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.entity.User;
import tech.aistar.service.IUserService;

import java.sql.Wrapper;
import java.util.List;

@RestController  //@Controller(当前这个类要注入到spring容器中)+@ResponseBody(方法返回值为json)
public class UserJsonController {

    @Autowired //表示当前类依赖于 IUserService， 并且对象从Spring容器中通过类型匹配获得
    private IUserService userService;
    //根据主键查询
    //url: http://localhost:8080:/springboot_demo/userjson/1
    @GetMapping("userjson/{userId}")
    public User getById(@PathVariable("userId") Integer userId){//@PathVariable:从URL路径中传过来的参数
        User user=userService.getById(userId);
        return user;
    }

    @GetMapping("userjson")
    public List<User> getByAll(){
        List<User> userList=userService.list();
        return userList;
    }
    //根据名称精确查询
    @GetMapping("userjson/name/{userName}")
    public User getByName(@PathVariable("userName") String userName){
        User user=userService.getByName(userName);
        return user;
    }
    //根据名称模糊查询
    @GetMapping("userjson/Likename/{userName}")
    public List<User> getByLikeName(@PathVariable("userName") String userName){
        List<User> userList=userService.getLikeUser(userName);
        return userList;
    }

    @GetMapping("userjson/page/{pageNum}")
    public Page<User> getByPage(@PathVariable("pageNum") Integer pageNum){
        Page<User> pageInfo =userService.getByPage(pageNum);
        return pageInfo;
    }
}
